package com.example.albumhotpro;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlbumAdapter extends ArrayAdapter<Album> {
	ArrayList<Album> list;
	LayoutInflater vi;
	int Resource;
	viewHolder holder;
	public AlbumAdapter(Context context, int resource, ArrayList<Album> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		vi = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		Resource = resource;
		list = objects;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			holder = new viewHolder();
			v = vi.inflate(Resource, null);
			holder.tvId = (TextView) v.findViewById(R.id.id);
			holder.tvArtist = (TextView) v.findViewById(R.id.artist);
			holder.tvTitle = (TextView) v.findViewById(R.id.title);
			v.setTag(holder);
		} else {
			holder = (viewHolder) v.getTag();
		}
		
		holder.tvId.setText(list.get(position).getId());
		holder.tvArtist.setText(list.get(position).getArtist());
		holder.tvTitle.setText(list.get(position).getTitle());
		return v;

	}
	static class viewHolder {
		public TextView tvId;
		public TextView tvArtist;
		public TextView tvTitle;

	}


}
